package com.easylinkin.linkappapi.quality.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityDrawingDTO;
import com.easylinkin.linkappapi.quality.entity.QualityDrawing;
import com.easylinkin.linkappapi.quality.service.QualityDrawingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 部位图纸管理
 */
@RestController
@RequestMapping("qualityDrawing")
@Api(tags = "部位图纸管理")
public class QualityDrawingController {
  
  @Autowired
  private QualityDrawingService qualityDrawingService;

  /**
   * @Description: 增加部位图纸
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping
  @ApiOperation("增加部位图纸")
  public RestMessage insert(@RequestBody QualityDrawing qualityDrawing){
    //todo 参数验证
    qualityDrawingService.insert(qualityDrawing);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 删除部位图纸（包含批量删除）
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping
  @ApiOperation("删除部位图纸（包含批量删除）")
  public RestMessage delBatch(@RequestBody QualityDrawing qualityDrawing){
    Assert.notEmpty(qualityDrawing.getIds(),"id不能为空");
    qualityDrawingService.removeByIds(qualityDrawing.getIds());
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 编辑部位图纸
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping
  @ApiOperation("编辑部位图纸")
  public RestMessage updateById(@RequestBody QualityDrawing qualityDrawing){
    Assert.notNull(qualityDrawing.getId(),"id不能为空");
    qualityDrawingService.updateOne(qualityDrawing);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询部位图纸详情
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询部位图纸详情")
  public RestMessage findById(@PathVariable("id")Long id) {
    Assert.notNull(id,"id不能为空");
    QualityDrawing qualityDrawing = qualityDrawingService.getById(id);
    return RestBuilders.successBuilder().data(qualityDrawing).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<QualityDrawing> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<QualityDrawingDTO> record =  qualityDrawingService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

